﻿Public Class tr : Inherits element

    Public Overrides Sub ResizeWidth(ByVal w As Integer)
        For Each td In Contents
            td.ResizeWidth(w)
        Next
    End Sub

    Public Overrides Sub Draw(ByVal g As System.Drawing.Graphics, ByVal P As System.Drawing.Point)
        For Each Item In Contents
            P.Offset(CellSpacing, 0)
            Item.Draw(g, P)
            P.Offset(Item.Width, 0)
        Next
    End Sub

    ReadOnly Property CellSpacing As Integer
        Get
            Return CType(Parent, table).CellSpacing
        End Get
    End Property

    Dim i As Integer
    Public Overrides Sub AddElement(ByVal e As element, ByRef Text As String)
        MyBase.AddElement(e, Text)
        Dim td As td = e
        CType(Parent, table).EnsureColumns(i + td.colspan - 1)
        td.Column = CType(Parent, table).columns(i)
        If td.Style.width <> "" Then
            If td.Column.style.width = "" Then
                td.Column.style.width = td.Style.width
            End If
        End If
        i += td.colspan
    End Sub

    Public Overrides ReadOnly Property Height As Integer
        Get
            Return Contents.Max(Function(x) x.Height)
        End Get
    End Property

    Public Overrides ReadOnly Property Width As Integer
        Get
            Return Contents.Sum(Function(x) x.Width) + CellSpacing * (Contents.Count + 1)
        End Get
    End Property

End Class